import type { HttpResponsePending } from '@/server/interface'
import type { NoticeList } from './components/NoticeSwiper/interface'
import { http } from '@/server'

export type FetchHomeDataProps = Partial<{
    /** 省编码 */
    province: string
    /** 年份 - 开班排行榜 */
    year: string
    /** 年份 - 开班统计 */
    years: string
    /** 课程id */
    course_id: string
    /** 课程类别id */
    category_id: string
}>

export const fetchHomeData = async (params?: FetchHomeDataProps) => {
    try {
        const { data } = await http.get('/engineer/home', {
            params,
        })
        return data
    } catch (error) {
        return undefined
    }
}

/** 获取培训班类别 */
export const fetchClassCategory = (): HttpResponsePending<Record<string, string>> =>
    http.get('/engineer/course/category-data')

/** 获取首页通知公告 */
export const fetchNoticeList = async () => {
    try {
        const { data } = await http.get<NoticeList.Data[]>('/engineer/notice/get-limit')

        return data
    } catch (error) {
        return []
    }
}
